package hot100;

public class sortColors {
    void swap(int[] nums,int l,int r) {
        int temp = nums[l];
        nums[l] = nums[r];
        nums[r] = temp;
    }
    public void sortColors(int[] nums) {
        //(0,l)是0的区间，(l,(n-r))是1的区间，(r,n)是2的区间
        int n = nums.length;
        int l = -1;
        int i = 0;
        int r = n;
        while(i < r) {
            if(nums[i] < 1) {
                swap(nums,++l,i++);
            }else if ( nums[i] == 1) {
                i++;
            }else {
                swap(nums,--r,i);
            }
        }

    }
}
